import { removeEmptyField } from '@/utils'
export default {
  created() {
    this.getList()
  },
  data() {
    return {
      title: '添加信息',
      formData: {},
      dialogVisible: false,
      listObj: {},
      listQuery: {
        page: 1
      }
    }
  },
  methods: {
    getList() {

    },
    search(query) {
      query = removeEmptyField(query)
      this.listQuery = Object.assign(this.listQuery, query)
      this.getList()
    },
    add() {
      this.title = '添加信息'
      this.dialogVisible = true
    },
    edit(row) {
      this.title = '修改信息'
      this.getOne(row)
    },
    del(row) {
      this.$confirm('此操作将永久删除该条记录, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.deleteOne(row)
        })
        .catch(() => {
          console.log('cancel')
        })
    },
    submit(formData) {
      formData = removeEmptyField(formData)
      if (!formData.id) {
        this.addOne(formData)
      } else {
        this.updateOne(formData)
      }
    },
    dialogClose() {
      this.formData = {}
    },
    _afterSubmit() {
      this.getList()
      this.formData = {}
      this.dialogVisible = false
    },
    reset() {
      this.listQuery = { page: 1 }
      this.getList()
    },
    changeCurrentPage(page) {
      this.listQuery.page = page
      this.getList()
    },
    changePagesize(pagesize) {
      this.listQuery.pagesize = pagesize
      this.getList()
    }
  }
}
